const express = require('express');
const { routeWrapper } = require('../../../lib/module/tool/route');
const router = express.Router();
const userSvc = require('../../../lib/service/user');

// 微信登录
router.post('/wxlogin', routeWrapper(async (req, res, next) => {
    return userSvc.wxUserLogin(req.body.code);
}, false));

// 获取用户数据
router.get('/getuserinfo', routeWrapper(async (req) => {
    return userSvc.getUserInfo(req.auth.userId);
}, true));

// 更新用户数据
router.post('/updateuserdata', routeWrapper(async (req) => {
    return userSvc.updateUserData(req.auth.userId, req.body.nickName, req.body.avatarUrl);
}, true));

// 更新用户手机
router.post('/updateuserphone', routeWrapper(async (req, res, next) => {
    return userSvc.updateUserPhone(req.auth.userId, req.body.encryptedData, req.body.iv);
}, true));

// 设置默认地址
router.post('/:areaId/setDefaultAddress', routeWrapper(async (req, res, next) => {
    return userSvc.setDefaultAddress(req.auth.userId, req.params.areaId, req.body.addressId);
}, true));

module.exports = router;
